package 算法.NiuKe.JZ;

import 算法.NiuKe.TreeNode;

import java.util.ArrayDeque;
import java.util.Queue;

/**
 * @author:谢君臣
 * @Date:2021/3/219:15
 * @version:1.0
 * @function: 操作给定的二叉树，将其变换为源二叉树的镜像。
 */
public class JZ18 {
    public static void main(String[] args) {

    }

    public TreeNode Mirror(TreeNode pRoot) {
        // write code here
        if (pRoot == null)
            return pRoot;
        Queue<TreeNode> tree = new ArrayDeque<>();
        tree.add(pRoot);
        while (!tree.isEmpty()) {
            TreeNode temp = tree.poll();
            if (temp != null) {
                TreeNode left = temp.left;
                TreeNode right = temp.right;
                temp.right = left;
                temp.left = right;
                if (left != null)
                    tree.add(left);
                if (right != null)
                    tree.add(right);
            }
        }
        return pRoot;
    }

}
